package leetcode.code1324;

import java.util.ArrayList;
import java.util.List;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public List<String> printVertically(String s) {
		String[] strings = s.split(" ");
		int m = strings.length;
		int n = 0;
		for (String str : strings) {
			if (str.length() > n) {
				n = str.length();
			}
		}
		char[][] arr = new char[m][n];
		for (int i = 0; i < arr.length; i++) {
			String str = strings[i];
			for (int j = 0; j < str.length(); j++) {
				arr[i][j] = str.charAt(j);
			}
		}
		List<String> ans = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			StringBuffer str = new StringBuffer();
			int index = 0;
			for (int j = 0; j < m; j++) {
				if (arr[j][i] != '\u0000') {
					index = j;
					str.append(arr[j][i]);
				}else {
					str.append(" ");
				}
			}
			ans.add(str.subSequence(0, index + 1).toString());
		}
		return ans;
	}

	@Override
	public void debug4() {
//		H.compare(getClass(), this.printVertically("HOW ARE YOU"));
		H.compare(getClass(), this.printVertically("TO BE OR NOT TO BE"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
